﻿using System;
using System.Collections.Generic;
using System.Linq;
using CSP.Bll.CommonBll;
using CSP.Bll.IObjectBlls;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Common.Factories;
using CSP.Dao;
using CSP.Model.CSP;
using CSP.Model.CSPEnum;
using CSP.Bll.DTO.ServiceInfo;
using CSP.Common.Tools;
using CSP.Dao.ObjectDaos.CSP.HB;

namespace CSP.Bll.ObjectBlls
{
    public class ServiceInfoBll : CSPCommonBll, IServiceInfoBll
    {
        /// <summary>
        /// 缓存键值
        /// </summary>
        private const string CACHEKEY = "ServiceInfo_";

        private const string CACHEKEYALL = "ServiceInfoBllAll";

        private CSPDaoFactory _factory;

        private IServiceInfoDao _serviceInfoDao;

        private ISearchServiceListDao _searchServiceListDao;

        public ServiceInfoBll()
        {
            _cacheProvider = CachedProviderFactory.GetLocalCachedProvider();
            _factory = CSPDaoFactory.GetInstance();
            _serviceInfoDao = _factory.GetServiceInfoDao();
            _searchServiceListDao = _factory.GetSearchServiceListDao();
        }

        public ICollection<Model.CSP.ServiceInfo> FindByUser(string userName, int pageIndex, int pageSize, out int pageCount)
        {
            //string cacheKey = CACHEKEY + userName + "_" + pageIndex + "_" + pageSize;
            //string cacheKeyCount = CACHEKEY + userName + "_" + pageIndex + "_" + pageSize + "Count";
            //依赖性Key 值，每个用户都会有一个依赖性Key值
            //string cacheKeyUser = CACHEKEY + userName;

            //ICollection<ServiceInfo> serviceInfo = _cacheProvider.GetData<Collection<ServiceInfo>>(cacheKey);
            //pageCount = _cacheProvider.GetData<int>(cacheKeyCount);
            //if (serviceInfo == null)
            //{
            ICollection<ServiceInfo> serviceInfo = _serviceInfoDao.FindByUser(userName, pageIndex, pageSize, out pageCount);

            ////定义失效时间
            //DateTime failureTime = DateTime.Now.AddMinutes(5);


            //if(pageIndex==0)
            //{
            //    _cacheProvider.AddData(cacheKeyUser, serviceInfo, failureTime);
            //    _cacheProvider.AddData(cacheKey, serviceInfo, failureTime, new string[] { cacheKeyUser });
            //    _cacheProvider.AddData(cacheKeyCount, serviceInfo, failureTime, new string[] { cacheKeyUser });
            //}

            //}

            return serviceInfo;
        }

        public Model.CSP.ServiceInfo GetDataById(int id)
        {
            string cacheKey = CACHEKEY + id.ToString();
            ServiceInfo serviceInfo = _cacheProvider.GetData<ServiceInfo>(cacheKey);
            if (serviceInfo == null)
            {
                //定义失效时间
                DateTime failureTime = DateTime.Now.AddMinutes(6);
                serviceInfo = _serviceInfoDao.GetDataById(id);
                _cacheProvider.AddData(cacheKey, serviceInfo, failureTime);
            }
            return serviceInfo;
        }

        /// <summary>
        /// 获取剩余服务量
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int GetSurplusEnjoyCountById(int id)
        {
            return _serviceInfoDao.GetSurplusEnjoyCountById(id);
        }

        public ICollection<ServiceInfo> FindAll()
        {
            //检测缓存是否存在
            ICollection<ServiceInfo> serviceInfos = _cacheProvider.GetData<ServiceInfo[]>(CACHEKEYALL);
            if (serviceInfos == null)
            {
                //从数据库读取数据
                serviceInfos = _serviceInfoDao.FindAll();
                _cacheProvider.AddData(CACHEKEYALL, serviceInfos, DateTime.Now.AddHours(2));
            }
            return serviceInfos;
        }
        public int GetCountByUserAndStatus(string userName, ServiceInfoStatus status)
        {
            return _serviceInfoDao.GetCountByUserAndStatus(userName, status);
        }

        public ServiceInfo GetByIdAndUser(int id, string userName)
        {
            return _serviceInfoDao.GetByIdAndUser(id, userName);
        }

        public ICollection<Model.CSP.ServiceInfo> GeDatatByIds(int[] Ids)
        {
            throw new NotImplementedException();
        }

        public void Add(Model.CSP.ServiceInfo obj)
        {
            CreateServiceInfo(obj);
        }

        /// <summary>
        /// 创建一个ServiceInfo  并返回创建成功的实例
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public ServiceInfo CreateServiceInfo(ServiceInfo obj)
        {
            //obj.SurplusEnjoyCount = obj.EnjoyCount.Value;
            ServiceInfo result = _serviceInfoDao.CreateServiceInfo(obj);

            //依赖性Key 值，每个用户都会有一个依赖性Key值
            string cacheKeyUser = CACHEKEY + obj.username;
            _cacheProvider.Remove(cacheKeyUser);
            return result;
        }

        public void Update(Model.CSP.ServiceInfo obj)
        {
            IOrderDao orderDao = _factory.GetOrderDao();
            IServiceImageDao serviceImageDao = _factory.GetServiceImageDao();
            int orderCount = orderDao.FindCountByServiceInfoId(obj.id);

            if (orderCount == 0)
            {
                ServiceInfo serviceInfo = GetServiceInfoByUpdateInfo(obj);
                _serviceInfoDao.Update(serviceInfo);
                foreach (var serviceImage in obj.ServiceImages)
                {
                    if (serviceImage.ImageOperateSatus == ImageOperateSatus.Deleted)
                    {
                        serviceImageDao.RemoveDataById(serviceImage.Id);
                    }
                }
            }
            else
            {
                int oldId = obj.id;
                //int oldId = 0;
                //obj.id = 0;

                obj.ServiceImages = CreateNewImgForSnapshotImg(obj.ServiceImages.ToList());
                obj.img = CreateNewImgForSnapshotImg(obj.img);
                ServiceInfo temServiceInfo = this.CreateServiceInfo(obj);
                //将当前数据定义为快照类型
                ServiceInfo oldServiceInfo = _serviceInfoDao.GetDataById(oldId);
                oldServiceInfo.status = (int)ServiceInfoStatus.Snapshot;
                oldServiceInfo.NewId = temServiceInfo.id;
                _serviceInfoDao.Update(oldServiceInfo);
            }
            //依赖性Key 值，每个用户都会有一个依赖性Key值
            string cacheKeyUser = CACHEKEY + obj.username;
            string cacheKey = CACHEKEY + obj.id;
            _cacheProvider.Remove(cacheKeyUser);
            _cacheProvider.Remove(cacheKey);

        }


        public ServiceInfo UpdateStatus(int id, ServiceInfoStatus serviceStatus)
        {
            ServiceInfo serviceInfo = _serviceInfoDao.UpdateStatus(id, serviceStatus);

            //依赖性Key 值，每个用户都会有一个依赖性Key值
            string cacheKeyUser = CACHEKEY + serviceInfo.username;
            _cacheProvider.Remove(cacheKeyUser);
            return serviceInfo;
        }

        public void DeleteById(int id)
        {
            throw new NotImplementedException();
        }

        public void RefreshCache()
        {
            throw new NotImplementedException();
        }


        public List<int> FindIdsByUser(string userName)
        {
            string cacheKeyUser = CACHEKEY + userName;
            List<int> serviceInfo = _cacheProvider.GetData<List<int>>(cacheKeyUser);
            if (serviceInfo == null || serviceInfo.Count == 0)
            {
                //定义失效时间
                DateTime failureTime = DateTime.Now.AddMinutes(5);
                serviceInfo = _serviceInfoDao.FindIdsByUser(userName);
                _cacheProvider.AddData(cacheKeyUser, serviceInfo, failureTime);
            }
            return serviceInfo;
        }

        public ICollection<ServiceInfo> FindByIds(List<int> ids, int pageIndex, int pageSize)
        {
            return _serviceInfoDao.FindByIds(ids, pageIndex, pageSize);
        }

        public List<int> FindIdsByIdsAndStatus(List<int> ids, ServiceInfoStatus status)
        {
            return _serviceInfoDao.FindIdsByIdsAndStatus(ids, status);
        }


        public List<int> FindByUserNameAndTitle(string userName, string title)
        {
            return _serviceInfoDao.FindByuserNameAndTitle(userName, title);
        }


        public ServiceInfo DeleteByIdAndUser(int id, string userName)
        {
            ServiceInfo result = null;

            IOrderDao orderDao = _factory.GetOrderDao();
            int orderCount = orderDao.FindCountByServiceInfoId(id);

            if (orderCount == 0)
            {
                result = _serviceInfoDao.DeleteByIdAndUser(id, userName);
            }
            else
            {
                result = _serviceInfoDao.UpdateStatus(id, ServiceInfoStatus.Snapshot);
            }

            return result;
        }

        /// <summary>
        /// 创建（快照）的新图片
        /// </summary>
        /// <param name="serviceImages"></param>
        /// <returns></returns>
        private ServiceImage[] CreateNewImgForSnapshotImg(List<ServiceImage> serviceImages)
        {
            string domainURL = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            for (int i = serviceImages.Count - 1; i >= 0; i--)
            {
                serviceImages[i].Id = 0;
                if (serviceImages[i].ImageOperateSatus == ImageOperateSatus.Original)
                {
                    string newFileName = CopyAndCreateNewFile(serviceImages[i].FilePath + serviceImages[i].FileName);

                    serviceImages[i].FilePath = newFileName.Substring(0, newFileName.LastIndexOf('/') + 1);
                    serviceImages[i].FileName = newFileName.Substring(newFileName.LastIndexOf('/') + 1);
                }
                else if (serviceImages[i].ImageOperateSatus == ImageOperateSatus.Deleted)
                {
                    serviceImages.RemoveAt(i);
                }

            }
            return serviceImages.ToArray();
        }

        /// <summary>
        /// 创建（快照的）的在线编辑器图片
        /// </summary>
        /// <param name="imgs"></param>
        /// <returns></returns>
        private string CreateNewImgForSnapshotImg(string imgs)
        {
            if (imgs == "")
            {
                return "";
            }

            List<string> images = imgs.Split('|').ToList();
            for (int i = images.Count - 1; i >= 0; i--)
            {
                string newFileName = CopyAndCreateNewFile(images[i]);
                if (newFileName == "")
                {
                    images.Remove(images[i]);
                }

            }
            return string.Join("|", images);
        }

        /// <summary>
        /// 复制并创建新文件
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private string CopyAndCreateNewFile(string fileName)
        {
            return ImageProviderFactory.GetInstance().CopyAndCreateNewImg("~" + fileName).Replace("~", "");
        }

        public List<SearchServiceList> GetDataByIdsDefault(List<int> ids, int pageIndex, int pageSize)
        {
            List<int> temIds = ids.Skip(pageIndex * pageSize).Take(pageSize).ToList();
            List<SearchServiceList> result = _searchServiceListDao.GetDataByIdsDefault(temIds, 0, pageSize);
            return result;

        }

        public List<SearchServiceList> GetDataByIdsOrderByOrderCount(List<int> ids, int pageIndex, int pageSize, bool isSortASC)
        {
            return _searchServiceListDao.GetDataByIdsOrderByOrderCount(ids, pageIndex, pageSize, isSortASC);
        }

        public List<SearchServiceList> GetDataByIdsOrderByServiceCredit(List<int> ids, int pageIndex, int pageSize, bool isSortASC)
        {
            return _searchServiceListDao.GetDataByIdsOrderByServiceCredit(ids, pageIndex, pageSize, isSortASC);
        }

        public List<SearchServiceList> GetDataByIdsOrderByPrice(List<int> ids, int pageIndex, int pageSize, bool isSortASC)
        {
            return _searchServiceListDao.GetDataByIdsOrderByPrice(ids, pageIndex, pageSize, isSortASC);
        }

        public List<int> FindIdsBySearchInfo(FindIdsBySearchInfoRequestDTO request)
        {
            List<int> result = new List<int>();
            ISearchCacheDao searchCacheDao = _factory.GetSearchCacheDao();
            ISearchInfoDao searchInfoDao = _factory.GetSearchInfoDao();

            if ((request.Area != null && request.AreaLeave == null) && (request.Area == null && request.AreaLeave != null))
            {
                throw new Exception("Area 和 AreaLeave 必须是同为空，或者 同不为空");
            }

            List<int> searchCondition = new List<int>();


            List<SearchCache> searchCaches = searchCacheDao.FindSearchCacheBySearchInfo(request.ServiceType, request.Area, request.AgeGroupType, request.SearchValue);

            //定义条件排查检索流程
            SearchProcess searchProcess = SearchProcess.FullCondition;

            //1.正式条件 优先级1
            SearchCache searchCache = GetSearchCacheBySearchCache(searchCaches, request.ServiceType, request.Area,request.AgeGroupType,request.SearchValue);

            //去掉一个SearchValue条件 查找是否存在
            if (searchCache == null)
            {
                searchCache = GetSearchCacheBySearchCache(searchCaches, request.ServiceType, request.Area, request.AgeGroupType, "");
                searchProcess = SearchProcess.SearchByAgeAndAreaAndType;
            }

            //再去掉一个ageGroupType条件 查找是否存在
            if (searchCache == null)
            {
                searchCache = GetSearchCacheBySearchCache(searchCaches, request.ServiceType, request.Area, null, "");

                searchProcess = SearchProcess.SearchByAreaAndType;
            }

            //再去掉一个ServiceArea 条件 查找是否存在
            if (searchCache == null)
            {
                searchCache = GetSearchCacheBySearchCache(searchCaches, request.ServiceType, null, null, "");
                searchProcess = SearchProcess.SearchByType;
            }

            if (searchCache == null)
            {
                searchProcess = SearchProcess.SearchNothing;
            }
            if (searchCache != null)
            {
                searchCondition = _cacheProvider.GetData<List<int>>(searchCache.CacheKey);
                if (searchCondition == null || searchCondition.Count == 0)
                {
                    searchCacheDao.Remove(searchCache);
                }
            }


            if (searchCondition == null || searchCondition.Count == 0)
            {
                searchProcess = SearchProcess.SearchNothing;
            }
            result = GetIdsBySearchDTOAndProcessAndSearchIds(request, searchProcess, searchCondition);

            return result;
        }

        /// <summary>
        /// 搜索引擎参数获取数据
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>

        /// <summary>
        /// 根据排查流程、请求的dto和服务Ids 查找数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="searchProcess"></param>
        /// <param name="ids"></param>
        /// <returns></returns>
        private List<int> GetIdsBySearchDTOAndProcessAndSearchIds(FindIdsBySearchInfoRequestDTO request, SearchProcess searchProcess, List<int> ids)
        {
            if (searchProcess == SearchProcess.FullCondition)
            {
                return ids;
            }
            SearchCache searchCache = new SearchCache();

            ISearchInfoDao searchInfoDao = _factory.GetSearchInfoDao();

            if (searchProcess == SearchProcess.SearchNothing && request.ServiceType != null)
            {
                List<ServiceType> serviceTypes = new List<ServiceType>();
                using (IServiceTypeBll serviceTypeBll = new ServiceTypeBll())
                {
                    serviceTypes = serviceTypeBll.FindAllByAvailable().ToList();
                }
                ServiceType serviceType = serviceTypes.FirstOrDefault(s => s.Id == request.ServiceType.Value);
                List<int> serviceTypeIds = new List<int>();
                if (serviceType.Level == 2)
                {
                    serviceTypeIds = serviceTypes.Where(s => s.ParentId == serviceType.Id).Select(s => s.Id).ToList();
                }
                else
                {
                    serviceTypeIds.Add(request.ServiceType.Value);
                }
                //获取服务类型
                ids = searchInfoDao.FindServiceIdsByServiceTypeIdAndServiceIds(serviceTypeIds, ids);

                //如果 服务类型查询 数据不存在那么以下条件将没必要查询
                if (ids.Count == 0)
                {
                    return ids;
                }
                searchCache.ServiceType = request.ServiceType;
                CreateSearchCache(searchCache, ids);
            }

            if ((searchProcess == SearchProcess.SearchByType || searchProcess == SearchProcess.SearchNothing) && request.Area != null)
            {
                //获取服务地址
                if ((int)AreaType.Province == request.AreaLeave)
                {
                    ids = searchInfoDao.FindServiceIdsByProvinceIdAndServiceIds(request.Area.Value, ids);
                }
                else if ((int)AreaType.City == request.AreaLeave)
                {
                    ids = searchInfoDao.FindServiceIdsByCityIdAndServiceIds(request.Area.Value, ids);
                }
                else //((int)AreaType.Contry== request.AreaLeave)
                {
                    ids = searchInfoDao.FindServiceIdsByCountyIdAndServiceIds(request.Area.Value, ids);
                }
                //如果 服务地址查询 数据不存在那么以下条件将没必要查询
                if (ids.Count == 0)
                {
                    return ids;
                }
                searchCache.ServiceArea = request.Area;
                CreateSearchCache(searchCache, ids);
            }

            if ((searchProcess == SearchProcess.SearchByAreaAndType || searchProcess == SearchProcess.SearchByType
                || searchProcess == SearchProcess.SearchNothing) && request.AgeGroupType != null)
            {
                //获取服务年龄
                List<int> ageGroup = new List<int>();// GetStartAgeAndEndAgeByAgeGroupType(request.AgeGroupType);
                ids = searchInfoDao.FindServiceIdsByStartAgeAndEndAgeAndServiceIds(ageGroup[0], ageGroup[1], ids);

                //如果服务年龄 查询 数据不存在那么以下条件将没必要查询
                if (ids.Count == 0)
                {
                    return ids;
                }

                //searchCache.AgeGroup = request.AgeGroupType == string.Empty ? string.Empty : request.AgeGroupType;
                CreateSearchCache(searchCache, ids);
            }

            if ((searchProcess == SearchProcess.SearchByAgeAndAreaAndType || searchProcess == SearchProcess.SearchByAreaAndType || searchProcess == SearchProcess.SearchByType
                || searchProcess == SearchProcess.SearchNothing) && !string.IsNullOrWhiteSpace(request.SearchValue))
            {
                //获取服务年龄
                ids = searchInfoDao.FindServiceIdsBySearchValueAndServiceIds(request.SearchValue, ids);

                //如果服务年龄 查询 数据不存在那么以下条件将没必要查询
                if (ids.Count == 0)
                {
                    return ids;
                }

                searchCache.SearchValue = request.SearchValue;
                CreateSearchCache(searchCache, ids);
            }
            return ids;
        }

        /// <summary>
        /// 创建缓存表根据搜索缓存，和ids
        /// </summary>
        /// <param name="searchCache"></param>
        /// <param name="ids"></param>
        private void CreateSearchCache(SearchCache searchCache, List<int> ids)
        {

            if (ids == null || ids.Count == 0)
            {
                return;
            }
            ISearchCacheDao searchCacheDao = _factory.GetSearchCacheDao();
            string cacheKey = CommonTool.GetGUIDForDateTime();
            searchCache.CacheKey = cacheKey;
            searchCache.CreateTime = DateTime.Now;
            if (searchCache.SearchValue == null)
            {
                searchCache.SearchValue = "";
            }
            searchCacheDao.Add(searchCache);
            _cacheProvider.AddData(cacheKey, ids, DateTime.Now.AddMinutes(10));

        }

        private SearchCache GetSearchCacheBySearchCache(List<SearchCache> searchCaches, int? serviceType, int? area, string ageGroupType, string searchValue)
        {
            SearchCache searchCache = searchCaches.FirstOrDefault(s => s.ServiceType == serviceType && s.ServiceArea == area && s.SearchValue == searchValue);
            if (searchCache != null)
            {
                if (searchCache.CreateTime.AddMinutes(-10) > DateTime.Now)
                {
                    ISearchCacheDao searchCacheDao = _factory.GetSearchCacheDao();
                    searchCacheDao.Remove(searchCache);
                    searchCaches.Remove(searchCache);
                }
                else
                {
                    return searchCache;
                }
            }
            return null;
        }

        /// <summary>
        /// 根据客户端传入的serviceInfo 整理需要保存的serviceInfo
        /// </summary>
        /// <param name="serviceInfo"></param>
        /// <returns></returns>
        private ServiceInfo GetServiceInfoByUpdateInfo(ServiceInfo serviceInfo)
        {
            ServiceInfo result = _serviceInfoDao.GetDataById(serviceInfo.id);//GetDataById(serviceInfo.id);


            //foreach (var serviceInfoAddressRel in serviceInfo.ServiceInfoAddressRels)
            //{
            //    serviceInfoAddressRel.ServiceInfoId = serviceInfo.id;
            //}
            //foreach (var serviceInfoServiceTypeRel in serviceInfo.ServiceInfoServiceTypeRels)
            //{
            //    serviceInfoServiceTypeRel.ServiceInfoId = serviceInfo.id;
            //}
            //result.id = serviceInfo.id;
            result.username = serviceInfo.username;
            result.img = serviceInfo.img;
            result.title = serviceInfo.title;
            result.Description = serviceInfo.Description;
            result.ServiceInfoServiceTypeRels.FirstOrDefault().ServiceTypeId = serviceInfo.ServiceInfoServiceTypeRels.FirstOrDefault().ServiceTypeId;
            //ServiceTypeId = Convert.ToInt32(this.Server.UrlDecode(Request["InfoType"]).Split(',')[2].Split('|')[1]),
            result.PriceType = serviceInfo.PriceType;
            result.PriceStart = serviceInfo.PriceStart;
            result.PriceEnd = serviceInfo.PriceEnd;
            result.Price = serviceInfo.Price;
            result.PriceUnitId = serviceInfo.PriceUnitId;
            result.OriginalPrice = serviceInfo.OriginalPrice;
            result.OriginalPriceUnitld = serviceInfo.OriginalPriceUnitld;

            result.ServiceInfoAddressRels.FirstOrDefault().AddressId = serviceInfo.ServiceInfoAddressRels.FirstOrDefault().AddressId;
            //AddressId = Convert.ToInt32(this.R_Address.SelectedValue),
            result.ClassOfMemberNumber = serviceInfo.ClassOfMemberNumber;
            result.AgeStart = serviceInfo.AgeStart;
            result.AgeEnd = serviceInfo.AgeEnd;
            result.ClassTypeId = serviceInfo.ClassTypeId;
            result.ClassValidityStart = serviceInfo.ClassValidityStart;
            result.ClassValidityEnd = serviceInfo.ClassValidityEnd;
            result.EnjoyCount = serviceInfo.EnjoyCount;
            result.KeyWords = serviceInfo.KeyWords;
            result.Content = serviceInfo.Content;
            result.img = serviceInfo.img;
            result.status = serviceInfo.status;
            result.LastModified = serviceInfo.LastModified;
            result.OnLineTime = serviceInfo.OnLineTime;
            foreach (var serviceImage in serviceInfo.ServiceImages)
            {



                if (serviceImage.ImageOperateSatus == ImageOperateSatus.Deleted)
                {

                    //IList<ServiceImage> serviceImages = result.ServiceImages;
                    //serviceImage.
                    //result.ServiceImages.FirstOrDefault(s => s.Id == serviceImage.Id).ServiceInfoId=0;
                    //result.ServiceImages.FirstOrDefault(s => s.Id == serviceImage.Id).ServiceInfoId = 0;
                    //ServiceImage temServiceImage=result.ServiceImages.FirstOrDefault(s => s.Id == serviceImage.Id);

                    //result.ServiceImages.Remove(temServiceImage);
                    //foreach(var temServiceImage in result.ServiceImages){
                    //    if(temServiceImage.Id==serviceImage.Id)
                    //    {
                    //        temServiceImage = null;
                    //    }
                    //}

                }
                else if (serviceImage.ImageOperateSatus == ImageOperateSatus.Added)
                {
                    result.ServiceImages.Add(serviceImage);
                }
                else if (serviceImage.ImageOperateSatus == ImageOperateSatus.Original)
                {
                    ServiceImage temServiceImage = result.ServiceImages.FirstOrDefault(s => s.Id == serviceImage.Id);
                    temServiceImage.OrderId = serviceImage.OrderId;
                }
            }
            result.OnLineTime = serviceInfo.OnLineTime;
            result.CreateTime = DateTime.Now;

            return result;
        }

        private List<int> GetStartAgeAndEndAgeByAgeGroupType(AgeGroupType ageGroupType)
        {
            List<int> result = new List<int>();
            switch (ageGroupType)
            {
                case AgeGroupType.OneToThree:
                    {
                        result.Add(1);
                        result.Add(3);
                        break;
                    }
                case AgeGroupType.ThreeToSix:
                    {
                        result.Add(3);
                        result.Add(6);
                        break;
                    }
                case AgeGroupType.SixToNine:
                    {
                        result.Add(6);
                        result.Add(9);
                        break;
                    }
                case AgeGroupType.NineToTwelve:
                    {
                        result.Add(9);
                        result.Add(12);
                        break;
                    }
                case AgeGroupType.TwelveToFifteen:
                    {
                        result.Add(12);
                        result.Add(15);
                        break;
                    }
                default:
                    {
                        result.Add(12);
                        result.Add(15);
                        break;
                    }
            }
            return result;
        }

        private enum AreaType
        {
            /// <summary>
            /// 省份
            /// </summary>
            Province = 1,

            /// <summary>
            /// 城市
            /// </summary>
            City = 2,

            /// <summary>
            /// 城镇
            /// </summary>
            County = 3,

        }

        private enum SearchProcess
        {
            /// <summary>
            /// 完整条件
            /// </summary>
            FullCondition = 0,

            /// <summary>
            /// 根据年龄,地区,服务类型条件
            /// </summary>
            SearchByAgeAndAreaAndType = 1,

            /// <summary>
            /// 根据地区和类型搜索
            /// </summary>
            SearchByAreaAndType = 2,

            /// <summary>
            /// 根据服务类型检索
            /// </summary>
            SearchByType = 3,

            /// <summary>
            /// 未搜索到数据
            /// </summary>
            SearchNothing = 4,
        }





        public SearchServiceListResponseDTO FindBySearchServiceList(SearchServiceListRequestDTO request)
        {

            SearchServiceListApp __searchServiceListApp = new SearchServiceListApp();
            return __searchServiceListApp.FindBySearchServiceList(request);
        }
    }
}
